# -*- coding: utf-8 -*-

'''eof
name:市场类别
code:MarketCategory
tableName:
columnName:
groups:烟商
dependencies:BTM
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import datetime

reload(sys)
sys.setdefaultencoding('utf-8')

def MarketCategory():
    null_type_list = ['', 'null', None, '/', 'Null', ' ']
    market_type = ['城市', '城镇', '乡村', '其他']
    try:
        BTM_ = BTM['data']
    except:
        return u'缺失值'

    try:
        if BTM_.has_key('indent') and BTM_['indent'] not in null_type_list \
                and BTM_.has_key('marketcategory') and BTM_['marketcategory'] not in null_type_list:
            if u'城市' in BTM_['marketcategory']:
                return u'城市'
            elif u'城镇' in BTM_['marketcategory'] or u'乡镇' in BTM_['marketcategory'] \
                    or u'村镇' in BTM_['marketcategory']  or u'集镇' in BTM_['marketcategory']:
                return u'城镇'
            elif u'乡村' in BTM_['marketcategory'] or u'农村' in BTM_['marketcategory']:
                return u'乡村'
            elif u'其他' in BTM_['marketcategory']:
                return u'其他'
            else:
                return u'缺失值'
        else:
            return u'缺失值'
    except:
        return u'缺失值'

result = MarketCategory()